/* 
 * File:   server.h
 * Author: Faraj
 *
 * Created on May 6, 2013, 10:38 PM
 */

#ifndef SERVER_H
#define	SERVER_H

#include <string>
#include <sys/types.h>
#include <stdio.h>
#include "../lib/common/log.h"
#include "../headers/microhttpd.h"
using namespace std;

typedef int (*web_connection_performer)(void *cls,
        struct MHD_Connection *connection,
        const char *url, const char *method,
        const char *version, const char *upload_data,
        size_t *upload_data_size, void **con_cls);

namespace lib {

    class server {
    public:
        server();
        virtual ~server();
        MHD_Daemon* start();
        void stop();
        bool is_running();
        string get_addr();
        int get_port();
        void set_addr(string addr);
        MHD_Daemon* get_daemon();
        void set_port(int port);
        void set_perform(web_connection_performer _performer);
    protected:
        string _addr;
        int _port;
        bool _running;
        struct MHD_Daemon *_daemon;
        web_connection_performer _performer;
    };
};
#endif	/* SERVER_H */

